package br.com.fafica.sisape.repositorioarray;

import java.util.ArrayList;

import br.com.fafica.sisape.model.Exame;;

public class RepositorioExame implements InterfaceRepositorioExame {
	
	static ArrayList <Exame> exames = new ArrayList<Exame>();
	static Integer cod = 0;
	
	/* (non-Javadoc)
	 * @see br.com.fafica.sisape.repositorioarray.InterfaceRepositorioExame#createExame(br.com.fafica.sisape.model.Exame, java.lang.Integer)
	 */
	@Override
	public void createExame(Exame exame, Integer codUsuario){
		cod++;
		exame.setCod(cod);
		exame.setCodUsuario(codUsuario);
		exames.add(exame);
	}
	/* (non-Javadoc)
	 * @see br.com.fafica.sisape.repositorioarray.InterfaceRepositorioExame#readExame(java.lang.Integer)
	 */
	@Override
	public ArrayList readExame(Integer cod){
		
		ArrayList<Exame> listaExame = new ArrayList<>();
		Exame e = new Exame();
		for(int i=0; i < exames.size(); i++){
			e = exames.get(i);
			if(e.getCodUsuario() == cod){
				listaExame.add(e);
			}
		}
		return listaExame;
	}
	/* (non-Javadoc)
	 * @see br.com.fafica.sisape.repositorioarray.InterfaceRepositorioExame#updateExame(br.com.fafica.sisape.model.Exame)
	 */
	@Override
	public void updateExame(Exame e){
		
		for(int i = 0; i < exames.size(); i++){
			if(exames.get(i).getCod() == e.getCod()){
				exames.set(i, e);
			}
		}
	}
	/* (non-Javadoc)
	 * @see br.com.fafica.sisape.repositorioarray.InterfaceRepositorioExame#deleteExame(br.com.fafica.sisape.model.Exame)
	 */
	@Override
	public void deleteExame(Exame e){
		
		for(int i = 0; i < exames.size(); i++){
			if(exames.get(i).getCod() == e.getCod()){
				exames.remove(i);
			}
		}
	}

}
